﻿using Mapster;
using RsCms.Application.Tags.Dto;
using RsCms.Core;
using RsCms.Core.Tags;
using RsCode;



namespace RsCms.Application.Tags
{
    public class TagsAppService:ITagsAppService
    {
        ITagsDomainService tagsDomainService;
        ITagsRepository tagsRepository;
        public TagsAppService(ITagsDomainService tagDomainService,ITagsRepository tagsRepository)
        {
            this.tagsDomainService = tagDomainService;
            this.tagsRepository = tagsRepository;
        }

        public async  Task<PageData<TagsDto>> PageAsync(int page, int pageSize)
        {
            var info=await tagsDomainService.PageAsync(page, pageSize);
            return info.Adapt<PageData<TagsDto>>(); 
        }

        public async Task<TagsEditDto> SaveAsync(TagsEditDto dto)
        {
            var info = dto.Adapt<Entities.Tags>();
            info=await tagsDomainService.SaveAsync(info);
            return info.Adapt<TagsEditDto>();
        }

        public  Task DeleteAsync(string tagId)
        {
            tagsRepository.Delete(x => x.Id == tagId);
            return Task.CompletedTask;
        }

        public async Task<TagsEditDto>GetAsync(string id)
        {
             var info=await tagsRepository.Select.Where(x=>x.Id== id).ToOneAsync();
            return info.Adapt<TagsEditDto>();
        }
    }
}
